package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyPesticideCrop;
import com.ruoyi.ncpsy.service.INcpsyPesticideCropService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 喷洒农药记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/ncpsy/pestCrop")
public class NcpsyPesticideCropController extends BaseController
{
    @Autowired
    private INcpsyPesticideCropService ncpsyPesticideCropService;

    /**
     * 查询喷洒农药记录列表
     * */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyPesticideCrop ncpsyPesticideCrop)
    {
        startPage();
        List<NcpsyPesticideCrop> list = ncpsyPesticideCropService.selectNcpsyPesticideCropList(ncpsyPesticideCrop);
        return getDataTable(list);
    }

    /**
     * 导出喷洒农药记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:export')")
    @Log(title = "喷洒农药记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyPesticideCrop ncpsyPesticideCrop)
    {
        List<NcpsyPesticideCrop> list = ncpsyPesticideCropService.selectNcpsyPesticideCropList(ncpsyPesticideCrop);
        ExcelUtil<NcpsyPesticideCrop> util = new ExcelUtil<NcpsyPesticideCrop>(NcpsyPesticideCrop.class);
        util.exportExcel(response, list, "喷洒农药记录数据");
    }

    /**
     * 获取喷洒农药记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:query')")
    @GetMapping(value = "/{pesticideCropId}")
    public AjaxResult getInfo(@PathVariable("pesticideCropId") Long pesticideCropId)
    {
        return success(ncpsyPesticideCropService.selectNcpsyPesticideCropByPesticideCropId(pesticideCropId));
    }

    /**
     * 新增喷洒农药记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:add')")
    @Log(title = "喷洒农药记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyPesticideCrop ncpsyPesticideCrop) throws Exception {
        System.out.println("ncpsyPesticideCrop" + ncpsyPesticideCrop);
        return toAjax(ncpsyPesticideCropService.insertNcpsyPesticideCrop(ncpsyPesticideCrop));
    }

    /**
     * 修改喷洒农药记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:edit')")
    @Log(title = "喷洒农药记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyPesticideCrop ncpsyPesticideCrop)
    {
        return toAjax(ncpsyPesticideCropService.updateNcpsyPesticideCrop(ncpsyPesticideCrop));
    }

    /**
     * 删除喷洒农药记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:pestCrop:remove')")
    @Log(title = "喷洒农药记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticideCropIds}")
    public AjaxResult remove(@PathVariable Long[] pesticideCropIds)
    {
        return toAjax(ncpsyPesticideCropService.deleteNcpsyPesticideCropByPesticideCropIds(pesticideCropIds));
    }
}
